home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Main.bin / ColorModel.java < prev    next >
Text File  |  1998-09-22  |  3KB  |  116 lines

  1. /*
  2.  * @(#)ColorModel.java    1.13 98/07/01
  3.  *
  4.  * Copyright 1995-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  * 
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.awt.image;
  16.  
  17. /**
  18.  * A class that encapsulates the methods for translating from pixel values
  19.  * to alpha, red, green, and blue color components for an image.  This
  20.  * class is abstract.
  21.  *
  22.  * @see IndexColorModel
  23.  * @see DirectColorModel
  24.  *
  25.  * @version    1.13 07/01/98
  26.  * @author     Jim Graham
  27.  */
  28. public abstract class ColorModel {
  29.     private int pData;        // Placeholder for data for native functions
  30.  
  31.     protected int pixel_bits;
  32.  
  33.     private static ColorModel RGBdefault;
  34.  
  35.     /**
  36.      * Return a ColorModel which describes the default format for
  37.      * integer RGB values used throughout the AWT image interfaces.
  38.      * The format for the RGB values is an integer with 8 bits
  39.      * each of alpha, red, green, and blue color components ordered
  40.      * correspondingly from the most significant byte to the least
  41.      * significant byte, as in:  0xAARRGGBB
  42.      */
  43.     public static ColorModel getRGBdefault() {
  44.     if (RGBdefault == null) {
  45.         RGBdefault = new DirectColorModel(32,
  46.                           0x00ff0000,    // Red
  47.                           0x0000ff00,    // Green
  48.                           0x000000ff,    // Blue
  49.                           0xff000000    // Alpha
  50.                           );
  51.     }
  52.     return RGBdefault;
  53.     }
  54.  
  55.     /**
  56.      * Constructs a ColorModel which describes a pixel of the specified
  57.      * number of bits.
  58.      */
  59.     public ColorModel(int bits) {
  60.     pixel_bits = bits;
  61.     }
  62.  
  63.     /**
  64.      * Returns the number of bits per pixel described by this ColorModel.
  65.      */
  66.     public int getPixelSize() {
  67.     return pixel_bits;
  68.     }
  69.  
  70.     /**
  71.      * The subclass must provide a function which provides the red
  72.      * color compoment for the specified pixel.
  73.      * @return        The red color component ranging from 0 to 255
  74.      */
  75.     public abstract int getRed(int pixel);
  76.  
  77.     /**
  78.      * The subclass must provide a function which provides the green
  79.      * color compoment for the specified pixel.
  80.      * @return        The green color component ranging from 0 to 255
  81.      */
  82.     public abstract int getGreen(int pixel);
  83.  
  84.     /**
  85.      * The subclass must provide a function which provides the blue
  86.      * color compoment for the specified pixel.
  87.      * @return        The blue color component ranging from 0 to 255
  88.      */
  89.     public abstract int getBlue(int pixel);
  90.  
  91.     /**
  92.      * The subclass must provide a function which provides the alpha
  93.      * color compoment for the specified pixel.
  94.      * @return        The alpha transparency value ranging from 0 to 255
  95.      */
  96.     public abstract int getAlpha(int pixel);
  97.  
  98.     /**
  99.      * Returns the color of the pixel in the default RGB color model.
  100.      * @see ColorModel#getRGBdefault
  101.      */
  102.     public int getRGB(int pixel) {
  103.     return (getAlpha(pixel) << 24)
  104.         | (getRed(pixel) << 16)
  105.         | (getGreen(pixel) << 8)
  106.         | (getBlue(pixel) << 0);
  107.     }
  108.  
  109.     /* Throw away the compiled data stored in pData */
  110.     private native void deletepData();
  111.  
  112.     public void finalize() {
  113.     deletepData();
  114.     }
  115. }
  116.